home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 2004 April / SGI IRIX 6.5 Applications 2004 April.iso / dist / mozilla.idb / var / netscape / mozilla / run-mozilla.sh.z / run-mozilla.sh
Linux/UNIX/POSIX Shell Script  |  2004-01-06  |  11KB  |  458 lines

  1. #!/bin/sh
  2. #Tag 0x00010646
  3. #
  4. # The contents of this file are subject to the Netscape Public
  5. # License Version 1.1 (the "License"); you may not use this file
  6. # except in compliance with the License. You may obtain a copy of
  7. # the License at http://www.mozilla.org/NPL/
  8. #
  9. # Software distributed under the License is distributed on an "AS
  10. # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  11. # implied. See the License for the specific language governing
  12. # rights and limitations under the License.
  13. #
  14. # The Original Code is mozilla.org code.
  15. #
  16. # The Initial Developer of the Original Code is Netscape
  17. # Communications Corporation.  Portions created by Netscape are
  18. # Copyright (C) 1998 Netscape Communications Corporation. All
  19. # Rights Reserved.
  20. #
  21. # Contributor(s): 
  22. #
  23. #
  24. ## 
  25. ## Usage:
  26. ##
  27. ## $ run-mozilla.sh [options] [program] [program arguments]
  28. ##
  29. ## This script is meant to run a mozilla program from the mozilla
  30. ## source tree.  This is mostly useful to folks hacking on mozilla.
  31. ##
  32. ## The script will setup all the environment voodoo needed to make
  33. ## mozilla work.
  34. ##
  35. ## In the absence of a program being specified on the command line, the
  36. ## script determines which program to run in this order of existence.
  37. ##
  38. ##   1. The program named foo-bin where foo is the name of this script,
  39. ##      (e.g. rename this script as TestEmbed and it will look for
  40. ##      TestEmbed-bin).
  41. ##   2. The "viewer" executable.
  42. ##   3. The "mozilla-bin" executable
  43. #
  44. ## Standard shell script disclaimer blurb thing:
  45. ##
  46. ## This script is a hack.  It's brute force.  It's horrible.  
  47. ## It doesn't use Artificial Intelligence.  It doesn't use Virtual Reality.
  48. ## It's not perl.  It's not python.  It probably won't work unchanged on
  49. ## the "other" thousands of unices.  But it worksforme.  --ramiro
  50. ##
  51. ## If you have an improvement, patch, idea, whatever, on how to make this
  52. ## script better, post it here:
  53. ##
  54. ## news://news.mozilla.org/netscape.public.mozilla.patches
  55. ## news://news.mozilla.org/netscape.public.mozilla.unix
  56. ## 
  57. #
  58. ##
  59. ## Potential improvements:
  60. ##
  61. ## + Run from anywhere in the tree.
  62. ## + Run ldd on the program and report missing dlls
  63. ## + Deal with NSPR in the tree
  64. ## + All the other unices
  65. ##
  66. #
  67. cmdname=`basename "$0"`
  68. MOZ_DIST_BIN=`dirname "$0"`
  69. MOZ_DEFAULT_NAME="./${cmdname}-bin"
  70. MOZ_APPRUNNER_NAME="./mozilla-bin"
  71. MOZ_VIEWER_NAME="./viewer"
  72. MOZ_PROGRAM=""
  73.  
  74. exitcode=0
  75. #
  76. ##
  77. ## Functions
  78. ##
  79. ##########################################################################
  80. moz_usage()
  81. {
  82. echo "Usage:  ${cmdname} [options] [program]"
  83. echo ""
  84. echo "  options:"
  85. echo ""
  86. echo "    -g                   Run in debugger."
  87. echo "    --debug"
  88. echo ""
  89. echo "    -d debugger          Debugger to use."
  90. echo "    --debugger debugger"
  91. echo ""
  92. echo "  Examples:"
  93. echo ""
  94. echo "  Run the viewer"
  95. echo ""
  96. echo "    ${cmdname} viewer"
  97. echo ""
  98. echo "  Run the mozilla-bin binary"
  99. echo ""
  100. echo "    ${cmdname} mozilla-bin"
  101. echo ""
  102. echo "  Debug the viewer in a debugger"
  103. echo ""
  104. echo "    ${cmdname} -g viewer"
  105. echo ""
  106. echo "  Debug the mozilla-bin binary in gdb"
  107. echo ""
  108. echo "    ${cmdname} -g mozilla-bin -d gdb"
  109. echo ""
  110.     return 0
  111. }
  112. ##########################################################################
  113. moz_bail()
  114. {
  115.     message=$1
  116.     echo
  117.     echo "$cmdname: $message"
  118.     echo
  119.     exit 1
  120. }
  121. ##########################################################################
  122. moz_test_binary()
  123. {
  124.     binary=$1
  125.     if [ -f "$binary" ]
  126.     then
  127.         if [ -x "$binary" ]
  128.         then
  129.             return 1
  130.         fi
  131.     fi
  132.     return 0
  133. }
  134. ##########################################################################
  135. moz_get_debugger()
  136. {
  137.     debuggers="ddd gdb dbx bdb"
  138.     debugger="notfound"
  139.     done="no"
  140.     for d in $debuggers
  141.     do
  142.         moz_test_binary /bin/type
  143.         if [ $? -eq 1 ]
  144.         then
  145.             dpath=`type ${d} | awk '{print $3;}' | sed -e 's/\.$//'`    
  146.         else     
  147.             dpath=`which ${d}`    
  148.         fi
  149.         if [ -x "$dpath" ]
  150.         then
  151.             debugger=$dpath
  152.             break
  153.         fi
  154.     done
  155.     echo $debugger
  156.     return 0
  157. }
  158. ##########################################################################
  159. moz_run_program()
  160. {
  161.     prog=$MOZ_PROGRAM
  162.     ##
  163.     ## Make sure the program is executable
  164.     ##
  165.     if [ ! -x "$prog" ]
  166.     then
  167.         moz_bail "Cannot execute $prog."
  168.     fi
  169.     ##
  170.     ## Use md5sum to crc a core file.  If md5sum is not found on the system,
  171.     ## then dont debug core files.
  172.     ##
  173.     moz_test_binary /bin/type
  174.     if [ $? -eq 1 ]
  175.     then
  176.         crc_prog=`type md5sum 2>/dev/null | awk '{print $3;}' 2>/dev/null | sed -e 's/\.$//'`
  177.     else
  178.         crc_prog=`which md5sum 2>/dev/null`
  179.     fi
  180.     if [ -x "$crc_prog" ]
  181.     then
  182.         DEBUG_CORE_FILES=1
  183.     fi
  184.     if [ "$DEBUG_CORE_FILES" ]
  185.     then
  186.         crc_old=
  187.         if [ -f core ]
  188.         then
  189.             crc_old=`$crc_prog core | awk '{print $1;}' `
  190.         fi
  191.     fi
  192.     ##
  193.     ## Run the program
  194.     ##
  195.     "$prog" ${1+"$@"}
  196.     exitcode=$?
  197.     if [ "$DEBUG_CORE_FILES" ]
  198.     then
  199.         if [ -f core ]
  200.         then
  201.             crc_new=`$crc_prog core | awk '{print $1;}' `
  202.         fi
  203.     fi
  204.     if [ "$crc_old" != "$crc_new" ]
  205.     then
  206.         printf "\n\nOh no!  %s just dumped a core file.\n\n" $prog
  207.         printf "Do you want to debug this ? "
  208.         printf "You need a lot of memory for this, so watch out ? [y/n] "
  209.         read ans
  210.         if [ "$ans" = "y" ]
  211.         then
  212.             debugger=`moz_get_debugger`
  213.             if [ -x "$debugger" ]
  214.             then
  215.                 echo "$debugger $prog core"
  216.  
  217.                 # See http://www.mozilla.org/unix/debugging-faq.html
  218.                 # For why LD_BIND_NOW is needed
  219.                 LD_BIND_NOW=1; export LD_BIND_NOW
  220.  
  221.                 $debugger "$prog" core
  222.             else
  223.                 echo "Could not find a debugger on your system."
  224.             fi
  225.         fi
  226.     fi
  227. }
  228. ##########################################################################
  229. moz_debug_program()
  230. {
  231.     prog=$MOZ_PROGRAM
  232.     ##
  233.     ## Make sure the program is executable
  234.     ##
  235.     if [ ! -x "$prog" ]
  236.     then
  237.         moz_bail "Cannot execute $prog."
  238.     fi
  239.     if [ -n "$moz_debugger" ]
  240.     then
  241.         moz_test_binary /bin/type
  242.         if [ $? -eq 1 ]
  243.         then    
  244.             debugger=`type $moz_debugger | awk '{print $3;}' | sed -e 's/\.$//'` 
  245.         else
  246.             debugger=`which $moz_debugger` 
  247.         fi    
  248.     else
  249.         debugger=`moz_get_debugger`
  250.     fi
  251.     if [ -x "$debugger" ] 
  252.     then
  253.         echo "set args ${1+"$@"}" > /tmp/mozargs$$ 
  254. # If you are not using ddd, gdb and know of a way to convey the arguments 
  255. # over to the prog then add that here- Gagan Saksena 03/15/00
  256.         case `basename $debugger` in
  257.             gdb) echo "$debugger $prog -x /tmp/mozargs$$"
  258.                 $debugger "$prog" -x /tmp/mozargs$$
  259.         exitcode=$?
  260.                 ;;
  261.             ddd) echo "$debugger --debugger \"gdb -x /tmp/mozargs$$\" $prog"
  262.                 $debugger --debugger "gdb -x /tmp/mozargs$$" "$prog"
  263.         exitcode=$?
  264.                 ;;
  265.             *) echo "$debugger $prog ${1+"$@"}"
  266.                 $debugger "$prog" ${1+"$@"}
  267.         exitcode=$?
  268.                 ;;
  269.         esac
  270.         /bin/rm /tmp/mozargs$$
  271.     else
  272.         echo "Could not find a debugger on your system." 
  273.     fi
  274. }
  275. ##########################################################################
  276. ##
  277. ## Command line arg defaults
  278. ##
  279. moz_debug=0
  280. moz_debugger=""
  281. #
  282. ##
  283. ## Parse the command line
  284. ##
  285. while [ $# -gt 0 ]
  286. do
  287.   case $1 in
  288.     -g | --debug)
  289.       moz_debug=1
  290.       shift
  291.       ;;
  292.     -d | --debugger)
  293.       moz_debugger=$2;
  294.       if [ "${moz_debugger}" != "" ]; then
  295.     shift 2
  296.       else
  297.         echo "-d requires an argument"
  298.         exit 1
  299.       fi
  300.       ;;
  301.     *)
  302.       break;
  303.       ;;
  304.   esac
  305. done
  306. #
  307. ##
  308. ## Program name given in $1
  309. ##
  310. if [ $# -gt 0 ]
  311. then
  312.     MOZ_PROGRAM=$1
  313.     shift
  314. fi
  315. ##
  316. ## Program not given, try to guess a default
  317. ##
  318. if [ -z "$MOZ_PROGRAM" ]
  319. then
  320.     ##
  321.     ## Try this script's name with '-bin' appended
  322.     ##
  323.     if [ -x "$MOZ_DEFAULT_NAME" ]
  324.     then
  325.         MOZ_PROGRAM=$MOZ_DEFAULT_NAME
  326.     ## Try viewer (this should be deprecated)
  327.     ## 
  328.     elif [ -x "$MOZ_VIEWER_NAME" ]
  329.     then
  330.         MOZ_PROGRAM=$MOZ_VIEWER_NAME
  331.     ##
  332.     ## Try mozilla-bin
  333.     ## 
  334.     elif [ -x "$MOZ_APPRUNNER_NAME" ]
  335.     then
  336.         MOZ_PROGRAM=$MOZ_APPRUNNER_NAME
  337.     fi
  338. fi
  339. #
  340. #
  341. ##
  342. ## Make sure the program is executable
  343. ##
  344. if [ ! -x "$MOZ_PROGRAM" ]
  345. then
  346.     moz_bail "Cannot execute $MOZ_PROGRAM."
  347. fi
  348. #
  349. ##
  350. ## Set MOZILLA_FIVE_HOME
  351. ##
  352. MOZILLA_FIVE_HOME=$MOZ_DIST_BIN
  353.  
  354. if [ -z "$MRE_HOME" ]; then
  355.     MRE_HOME=$MOZILLA_FIVE_HOME
  356. fi
  357. ##
  358. ## Set LD_LIBRARY_PATH
  359. LD_LIBRARY_PATH=${MOZ_DIST_BIN}:${MOZ_DIST_BIN}/plugins:${MRE_HOME}${LD_LIBRARY_PATH+":$LD_LIBRARY_PATH"}
  360. if [ -n "$LD_LIBRARYN32_PATH" ]
  361. then
  362.     LD_LIBRARYN32_PATH=${MOZ_DIST_BIN}:${MOZ_DIST_BIN}/plugins:${MRE_HOME}${LD_LIBRARYN32_PATH+":$LD_LIBRARYN32_PATH"}
  363. fi
  364. if [ -n "$LD_LIBRARYN64_PATH" ]
  365. then
  366.     LD_LIBRARYN64_PATH=${MOZ_DIST_BIN}:${MOZ_DIST_BIN}/plugins:${MRE_HOME}${LD_LIBRARYN64_PATH+":$LD_LIBRARYN64_PATH"}
  367. fi
  368. if [ -n "$LD_LIBRARY_PATH_64" ]; then
  369.     LD_LIBRARY_PATH_64=${MOZ_DIST_BIN}:${MOZ_DIST_BIN}/plugins:${MRE_HOME}${LD_LIBRARY_PATH_64+":$LD_LIBRARY_PATH_64"}
  370. fi
  371. #
  372. #
  373. ## Set SHLIB_PATH for HPUX
  374. SHLIB_PATH=${MOZ_DIST_BIN}:${MRE_HOME}${SHLIB_PATH+":$SHLIB_PATH"}
  375. #
  376. ## Set LIBPATH for AIX
  377. LIBPATH=${MOZ_DIST_BIN}:${MRE_HOME}${LIBPATH+":$LIBPATH"}
  378. #
  379. ## Set DYLD_LIBRARY_PATH for Mac OS X (Darwin)
  380. DYLD_LIBRARY_PATH=${MOZ_DIST_BIN}:${MRE_HOME}${DYLD_LIBRARY_PATH+":$DYLD_LIBRARY_PATH"}
  381. #
  382. ## Set LIBRARY_PATH for BeOS
  383. LIBRARY_PATH=${MOZ_DIST_BIN}:${MOZ_DIST_BIN}/components:${MRE_HOME}${LIBRARY_PATH+":$LIBRARY_PATH"}
  384. #
  385. ## Set ADDON_PATH for BeOS
  386. ADDON_PATH=${MOZ_DIST_BIN}${ADDON_PATH+":$ADDON_PATH"}
  387. #
  388. ## Solaris Xserver(Xsun) tuning - use shared memory transport if available
  389. if [ "$XSUNTRANSPORT" = "" ]
  390. then 
  391.         XSUNTRANSPORT="shmem" 
  392.         XSUNSMESIZE="512"
  393.         export XSUNTRANSPORT XSUNSMESIZE
  394. fi
  395. ## Populate XPSERVERLIST if it was not set yet
  396. if [ "$XPSERVERLIST" = "" ]
  397. then
  398.     if [ -f /etc/init.d/xprint ] ; then
  399.         XPSERVERLIST="`/bin/sh /etc/init.d/xprint get_xpserverlist`"
  400.         if [ "$XPSERVERLIST" != "" ] ; then
  401.             export XPSERVERLIST
  402.         fi
  403.     fi
  404. fi
  405. # Font path for Xft
  406. FONTCONFIG_PATH="/etc/fonts:${MOZILLA_FIVE_HOME}/res/Xft"
  407. export FONTCONFIG_PATH
  408.  
  409. if [ "$moz_debug" -eq 1 ]
  410. then
  411.   echo "MOZILLA_FIVE_HOME=$MOZILLA_FIVE_HOME"
  412.   echo "  LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
  413.   if [ -n "$LD_LIBRARYN32_PATH" ]
  414.   then
  415.       echo "LD_LIBRARYN32_PATH=$LD_LIBRARYN32_PATH"
  416.   fi
  417.   if [ -n "$LD_LIBRARYN64_PATH" ]
  418.   then
  419.       echo "LD_LIBRARYN64_PATH=$LD_LIBRARYN64_PATH"
  420.   fi
  421.   if [ -n "$LD_LIBRARY_PATH_64" ]; then
  422.       echo "LD_LIBRARY_PATH_64=$LD_LIBRARY_PATH_64"
  423.   fi
  424.   if [ -n "$DISPLAY" ]; then
  425.        echo "DISPLAY=$DISPLAY"
  426.   fi
  427.   if [ -n "$FONTCONFIG_PATH" ]; then
  428.     echo "FONTCONFIG_PATH=$FONTCONFIG_PATH"
  429.   fi
  430.   if [ -n "$XPSERVERLIST" ]; then
  431.        echo "XPSERVERLIST=$XPSERVERLIST"
  432.   fi
  433.   if [ -n "$MOZILLA_POSTSCRIPT_PRINTER_LIST" ]; then
  434.        echo "MOZILLA_POSTSCRIPT_PRINTER_LIST=$MOZILLA_POSTSCRIPT_PRINTER_LIST"
  435.   fi
  436.   echo "DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH"
  437.   echo "     LIBRARY_PATH=$LIBRARY_PATH"
  438.   echo "       SHLIB_PATH=$SHLIB_PATH"
  439.   echo "          LIBPATH=$LIBPATH"
  440.   echo "       ADDON_PATH=$ADDON_PATH"
  441.   echo "      MOZ_PROGRAM=$MOZ_PROGRAM"
  442.   echo "      MOZ_TOOLKIT=$MOZ_TOOLKIT"
  443.   echo "        moz_debug=$moz_debug"
  444.   echo "     moz_debugger=$moz_debugger"
  445. fi
  446. #
  447. export MOZILLA_FIVE_HOME LD_LIBRARY_PATH
  448. export SHLIB_PATH LIBPATH LIBRARY_PATH ADDON_PATH DYLD_LIBRARY_PATH
  449.  
  450. if [ $moz_debug -eq 1 ]
  451. then
  452.     moz_debug_program ${1+"$@"}
  453. else
  454.     moz_run_program ${1+"$@"}
  455. fi
  456.  
  457. exit $exitcode
  458.